package com.ruoyi.web.controller.weixincp;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.weixincp.service.IWeiXinCpService;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.ParseException;

/**
 * 企业微信
 */
@RestController
@RequestMapping("/weixincpManager/weixincp")
public class WeiXinCpController extends BaseController {
    @Resource private IWeiXinCpService weiXinCpService;


    /**
     * 通过微信用户账号获取用户信息
     * @param userId
     * @return
     * @throws WxErrorException
     */
    @GetMapping("/getCpUserInfoById")
    public AjaxResult getCpUserInfoById(String userId) throws WxErrorException {
        return AjaxResult.success(weiXinCpService.getCpUserInfoById( userId ));
//        return null;
    }


    /**
     * 获取用户列表信息
     * @return
     * @throws WxErrorException
     */
    @GetMapping("/getCpUserInfoList")
    public AjaxResult getCpUserInfoList() throws WxErrorException {
        return AjaxResult.success(weiXinCpService.getCpUserInfoList( ));
//        return null;
    }


    /**
     * 获取部门列表信息
     * @return
     * @throws WxErrorException
     */
    @GetMapping("/getCpDeptList")
    public AjaxResult getCpDeptList() throws WxErrorException {
        return AjaxResult.success(weiXinCpService.getCpDeptList( ));
//        return null;
    }

    /**
     * 获取getToken
     * @return
     * @throws WxErrorException
     */
    @GetMapping("/getToken")
    public AjaxResult getToken() throws WxErrorException {
        return AjaxResult.success(weiXinCpService.getToken( ));
    }


    /**
     * 企业微信应用消息推送
     * @param sendUrl  推送跳转连接
     * @param fillTime  推送时间
     * @param sendUserName 推送人姓名
     * @return
     * @throws WxErrorException
     */
    @GetMapping("/sendApplicationMessage")
    public AjaxResult sendApplicationMessage( @RequestParam String sendUrl, @RequestParam String fillTime, @RequestParam String sendUserName) throws WxErrorException, ParseException {
        return weiXinCpService.sendApplicationMessage(sendUrl,fillTime,sendUserName );
    }

}
